<template>
  <div>
      <!-- 搜索栏 -->
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="操作人">
              <el-input v-model="formInline.exceptionUser" placeholder="请输入操作人"></el-input>
            </el-form-item>
            <el-form-item label="异常类型">
              <el-input v-model="formInline.exceptionType" placeholder="请输入异常类型"></el-input>
            </el-form-item>
            <el-form-item label="异常方法">
              <el-input v-model="formInline.exceptionMethod" placeholder="请输入异常方法"></el-input>
            </el-form-item>
            <el-form-item label="异常类">
              <el-input v-model="formInline.exceptionClass" placeholder="请输入异常类"></el-input>
            </el-form-item>
            <el-form-item label="异常方法的参数">
              <el-input v-model="formInline.exceptionArgs" placeholder="请输入异常方法的参数"></el-input>
            </el-form-item>
            <el-form-item label="异常描述">
              <el-input v-model="formInline.exceptionDescription" placeholder="请输入异常描述"></el-input>
            </el-form-item>
            <!-- 开始时间 -->
            <el-form-item class="block">
              <span class="demonstration">异常时间</span>
              <el-date-picker
                v-model="formInline.begin"
                type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择开始时间">
              </el-date-picker>
            </el-form-item>
            <!-- 结束时间 -->
            <el-form-item class="block">
              <span class="demonstration">异常时间</span>
              <el-date-picker
                v-model="formInline.end"
                type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择结束时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="getPageList" class="el-icon-search">查询</el-button>
            </el-form-item>
    </el-form>
  <!-- 主体表格 -->
  <el-table :data="exceptionLogList" stripe style="width: 100%">
    <el-table-column prop="operateUser" label="操作人" width="100"></el-table-column>
    <el-table-column prop="exceptionType" label="异常类型" width="300"></el-table-column>
    <el-table-column prop="exceptionMethod" label="异常方法" width="100"></el-table-column>
    <el-table-column prop="exceptionClass" label="异常类" width="300"></el-table-column>
    <el-table-column label="导致异常传入的参数" width="100">
      <template slot-scope="scope">
        <el-button class="el-icon-question" @click="openDetailDialog(scope.row)" type="primary" size="mini">查看详情</el-button>
      </template>
    </el-table-column>
    <el-table-column label="异常描述" width="100">
      <template slot-scope="scope">
        <el-button class="el-icon-question" @click="openDetailDialog(scope.row)" type="primary" size="mini">查看详情</el-button>
      </template>
    </el-table-column>
    <el-table-column prop="exceptionCreateTime" label="异常时间" width="300"></el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button class="el-icon-delete" type="danger" size="mini" @click=del(scope.row)>删除</el-button>
      </template>
    </el-table-column>
  </el-table>

  <!-- 分页条 -->
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[5, 8, 10, 20, 50, 100, 200, 500]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

  <!-- 详情表单 -->
  <el-dialog title="异常日志详情" :visible.sync="detailDialog">
  <el-form :model="exceptionLogDetail">
    <el-form-item label="操作人">
      <el-input v-model="exceptionLogDetail.operateUser" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="异常类型">
      <el-input v-model="exceptionLogDetail.exceptionType" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="异常方法">
      <el-input v-model="exceptionLogDetail.exceptionMethod" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="异常类">
      <el-input v-model="exceptionLogDetail.exceptionClass" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="异常方法传入的参数">
      <el-input type="textarea" v-model="exceptionLogDetail.exceptionArgs" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="异常描述">
      <el-input type="textarea" v-model="exceptionLogDetail.exceptionDescription" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="异常时间">
      <el-input v-model="exceptionLogDetail.exceptionCreateTime" autocomplete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="detailDialog = false">取 消</el-button>
    <el-button type="primary" @click="detailDialog = false">确 定</el-button>
  </div>
</el-dialog>
  </div>
</template>

<script>
import { getAll, getById, deleteById } from '@/api/exceptionLog.js'
export default {
  name: 'ExceptionPage',
  data () {
    return {
      exceptionLogList: [],
      page: 1,
      pageSize: 5,
      total: null,
      formInline: { // 模糊查询条件
        exceptionUser: null,
        exceptionType: null,
        exceptionMethod: null,
        exceptionClass: null,
        exceptionArgs: null,
        exceptionDescription: null,
        begin: null,
        end: null
      },
      detailDialog: false, // 详情框
      exceptionLogDetail: {}

    }
  },
  created () {
    this.getPageList()
  },
  methods: {
    // 查看详情
    async openDetailDialog (row) {
      this.detailDialog = true
      const res = await getById(row.id)
      console.log(res)
      this.exceptionLogDetail = res.data
    },
    // 删除异常日志
    del (row) {
      this.$confirm('确定删除该异常日志吗，删除后将无法恢复!', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确定删除',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await deleteById(row.id)
        console.log(res)
        this.getPageList()
        this.$message({
          type: 'success',
          message: '删除成功'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消删除'
        })
      })
    },
    // 分页查询
    async getPageList () {
      const { data } = await getAll(this.page, this.pageSize, this.formInline)
      this.exceptionLogList = data.records
      this.total = data.total
    },

    // 每页展示条数发生变化
    handleSizeChange (pageSize) {
      this.pageSize = pageSize
      this.getPageList()
    },
    // 页码发生变化
    handleCurrentChange (page) {
      this.page = page
      this.getPageList()
    }

  }
}
</script>

<style>

</style>
